package com.example.homeworkmutualevaluation.Dao;

import com.example.homeworkmutualevaluation.Entity.Bulletin;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;


public interface BulletinDao extends JpaRepository<Bulletin, Integer> {
    @Transactional
    @Modifying
    @Query(value = "UPDATE bulletin SET `title`=?1, `content`=?2 WHERE `id`=?1", nativeQuery = true)
    int update(int id, String title, String content);

    @Transactional
    @Modifying
    @Query(value = "DELETE FROM bulletin WHERE `id`=?1", nativeQuery = true)
    int delete(int id);

    @Query(value = "SELECT * FROM bulletin ORDER BY `datetime` DESC", nativeQuery = true)
    List<Bulletin> selectAll();
}
